if (typeof jQuery !== 'undefined') {
	(function($) {
		$('#spinner').ajaxStart(function() {
			$(this).fadeIn();
		}).ajaxStop(function() {
			$(this).fadeOut();
		});
	})(jQuery);
}

var $j = jQuery.noConflict(); 

jQuery(document).ready(function($j) {

	$j(".box-widget-head").click(function(){
		var divParent = $j(this).parent();
		var divParametrosConcreto = divParent.find('.box-widget-body');
		var divSalvar = divParent.find('.box-widget-footer');
		divParametrosConcreto.toggle(); 
		divSalvar.toggle(); 
	});
	

	// ##################
	// ## FORMATADORES ##
	// ##################
	
	$j('.mobileMask').mask("(99) 9999-9999?9");
   	$j('.phoneMask').mask("(99) 9999-9999");
   	$j('.cepMask').mask("99.999-999");
   	$j('.cpfMask').mask("999.999.999-99");
   	$j('.cnpjMask').mask("99.999.999/9999-99");
   	$j('.hora').mask("99:99");
   	$j('.dataMesAno').mask("99/9999");
   	
   	$j('.currencyFormat').formatCurrency();
   	$j('.currencyFormatSubmit').formatCurrency();
   	
    $j('.currencyFormat').change(function() {
        $j('.currencyFormat').formatCurrency();
   	});
    $j('.currencyFormatSubmit').change(function() {
        $j('.currencyFormatSubmit').formatCurrency();
        calcularServicoConcretagem($j(this).attr('id'), $j(this).attr('name'));	    	        
   	});
    
	$j('.currencyFormat').bind('keypress', function (event) {
		var regex = new RegExp("[0-9,\b]");
    	var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
	    if (!regex.test(key)) {
	       event.preventDefault();
	       return false;
	    }
   	});
	$j('.currencyFormatSubmit').bind('keypress', function (event) {
		var regex = new RegExp("[0-9,\b]");
    	var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
	    if (!regex.test(key)) {
	       event.preventDefault();
	       return false;
	    }
   	});
	
   	$j('.numberFormatSubmit').formatCurrency({
		symbol: ''
	});				
	$j('.numberFormatSubmit').change(function() {
	    $j('.numberFormatSubmit').formatCurrency({
			symbol: ''
		});
		calcularServicoConcretagem($j(this).attr('id'), $j(this).attr('name'));
   	});
   	$j('.numberFormatSubmit').bind('keypress', function (event) {
	        var regex = new RegExp("[0-9,\b]");
	    var key = String.fromCharCode(!event.charCode ? event.which : event.charCode);
	    if (!regex.test(key)) {
	       event.preventDefault();
	       return false;
	    }
   	});
   	
   	$j('.atualizarContato').click(function() {
   		atualizarContato($j(this).attr('id'), 'atualizarContato');
   	});

   	$j('form').submit(function() {
		$j('.currencyFormatSubmit').formatCurrency();
		$j('.currencyFormatSubmit').blur(function() {
   	        $j('.currencyFormatSubmit').formatCurrency();
       	});
		$j('.currencyFormat').formatCurrency();
		$j('.currencyFormat').blur(function() {
   	        $j('.currencyFormat').formatCurrency();
       	});
       	this.submit();
	});
   	
    jQuery('.datepicker').live('focus', function () {
        jQuery(".datepicker").datepicker({
			    dateFormat: 'dd/mm/yy',
			    dayNames: ['Domingo','Segunda','Terça','Quarta','Quinta','Sexta','Sábado'],
			    dayNamesMin: ['D','S','T','Q','Q','S','S','D'],
			    dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','Sáb','Dom'],
			    monthNames: ['Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
			    monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun','Jul','Ago','Set','Out','Nov','Dez'],
			    nextText: 'Próximo',
			    prevText: 'Anterior'
			});
     });
});
		
